<?php

include 'php-ofc-library/open-flash-chart.php';
include 'functions.php';

/* pre-flight check
    RULES:
	- a defined group invalidated hostnames
*/

// tell me how longhistory you wanna see in SECONDS
$intrval = 360; 
// list of a group you want to display (invalidate hostname list)
$group = "";
// an array of hosts (only valid if NO GROUP DEFINED!)
$hostname = array( "debvm" );
// name of check you want to draw
$check = "linux_processes";


/*
1. el kell donteni hogy host, vagy group alapjan megyunk e

*/


if (!empty($group)) {
    unset($hostname);
    $title = $check." on ". $group." group";
    $hostlist = get_hosts_for_group($group);
    $num_hosts = 0;
    $xlabs = get_time_for_host($hostlist[0], $intrval, $check);
    foreach ( $hostlist as $host ) {
	$data_arr[$num_hosts] = fetch_data_by_host($group,$host,$check,$intrval);
	$num_hosts++;
    }
} else {
// ide pedig bekell rakni host alapon
    $xlabs = get_time_for_host($hostname[0], $intrval, $check);
    if ( count($hostname) > 1 ) {
	$title = $check." on multiple hosts";
    } else {
	$title = $check." on ".$hostname[0];
    }
    $num_hosts = 0;
    foreach ( $hostname as $host ) {
	// egyenlore nincs jobb otletem majd csak lesz
	// feltoltjuk X tengelyt az elso host ertekevel
	$data_arr[$num_hosts] = fetch_data_by_host($group,$host,$check,$intrval);
	$num_hosts++;
    }


}

$g = new graph();
$g->title( $title, '{font-size: 18px;}' );

$b = 0;
while ($b < $num_hosts ) {
    $g->set_data( $data_arr[$b] );
    $b++;
}

// label each point with its value
$g->set_x_labels( $xlabs );


// time to build some statistics
foreach ( $data_arr as $perhostarr ) {
	foreach ($perhostarr as $value ) {
	    $all_vall[] = $value;
	}
}

$max = max($all_vall) * 1.5;
$g->set_y_max( ceil($max) );

$g->y_label_steps( 5 );
echo $g->render();
?>

